package com.ytc.www.controller;

import com.ytc.www.dto.PageDTO;
import com.ytc.www.dto.ResponseBox;
import com.ytc.www.dto.UserDTO;
import com.ytc.www.entity.EducationUser;
import com.ytc.www.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * online_education
 * com.ytc.www.controller
 *
 * @author 刘志伟
 * @create 2022-03-22 17:24
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping(value="/api/users/getAll")
    public ResponseBox<EducationUser> getAll(@RequestBody UserDTO userDTO, @RequestParam int gotoPage)
    {
        System.out.println("user provider invoked");
        PageDTO pageDTO=new PageDTO();

        pageDTO.setGotoPage(gotoPage);
        ResponseBox responseBox = userService.queryAll(userDTO,pageDTO);
        return responseBox;
    }

    @GetMapping(value = "/api/users/{id}")
    public ResponseBox<EducationUser> getById(@PathVariable("id") int id) {
        return userService.queryByUserId(id);
    }
    @DeleteMapping(value = "/api/users/{id}")
    public void delete(@PathVariable("id") int id) {
        userService.delete(id);
    }
    @PutMapping(value = "/api/users/")
    public void save(@RequestBody EducationUser user) {
        userService.insert(user);
    }
    @PostMapping(value = "/api/users/update")
    public ResponseBox<EducationUser> update(@RequestBody EducationUser user) {
        System.out.println("user provider invoked");
        return userService.update(user);
    }

}

